#include "clavier.h"
#include "ui_clavier.h"
#include <QMouseEvent>

Clavier::Clavier(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Clavier)
{
    ui->setupUi(this);
    //ui->ToucheOk->setVisible(false);
    mother = parent;
    ui->ToucheMaj->setVisible(false);
    ui->ToucheSpace->setVisible(false);
    ui->ToucheMaj->setCheckable(false);
    cache = false;
}

Clavier::Clavier(bool admin, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Clavier)
{
    ui->setupUi(this);
    //ui->ToucheOk->setVisible(admin);
    mother = parent;
    ui->ToucheSpace->setVisible(admin);
    ui->ToucheMaj->setVisible(admin);
    ui->ToucheMaj->setCheckable(admin);
    cache = false;
}

Clavier::~Clavier()
{
    delete ui;
}

void Clavier::ajouterMaj()
{
    ui->ToucheMaj->setVisible(true);
    ui->ToucheMaj->setCheckable(true);
}


void Clavier::on_ToucheA_pressed(){
    if(ui->ToucheMaj->isChecked()){
        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_A,Qt::ShiftModifier,"A",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{
        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_A,Qt::NoModifier,"a",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheB_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_B,Qt::ShiftModifier,"B",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_B,Qt::NoModifier,"b",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheC_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_C,Qt::ShiftModifier,"C",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_C,Qt::NoModifier,"c",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheD_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_D,Qt::ShiftModifier,"D",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_D,Qt::NoModifier,"d",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheE_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_E,Qt::ShiftModifier,"E",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_E,Qt::NoModifier,"e",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheF_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_F,Qt::ShiftModifier,"F",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_F,Qt::NoModifier,"f",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheG_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_G,Qt::ShiftModifier,"G",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_G,Qt::NoModifier,"g",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheH_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_H,Qt::ShiftModifier,"H",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_H,Qt::NoModifier,"h",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheI_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_I,Qt::ShiftModifier,"I",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_I,Qt::NoModifier,"i",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheJ_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_J,Qt::ShiftModifier,"J",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_J,Qt::NoModifier,"j",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheK_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_K,Qt::ShiftModifier,"K",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_K,Qt::NoModifier,"k",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheL_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_L,Qt::ShiftModifier,"L",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_L,Qt::NoModifier,"l",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheM_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_M,Qt::ShiftModifier,"M",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_M,Qt::NoModifier,"m",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheN_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_N,Qt::ShiftModifier,"N",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_N,Qt::NoModifier,"n",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheO_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_O,Qt::ShiftModifier,"O",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_O,Qt::NoModifier,"o",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}


void Clavier::on_ToucheP_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_P,Qt::ShiftModifier,"P",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_P,Qt::NoModifier,"p",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheQ_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Q,Qt::ShiftModifier,"Q",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Q,Qt::NoModifier,"q",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheR_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_R,Qt::ShiftModifier,"R",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_R,Qt::NoModifier,"r",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);

    }
}

void Clavier::on_ToucheS_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_S,Qt::ShiftModifier,"S",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_S,Qt::NoModifier,"s",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheT_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_T,Qt::ShiftModifier,"T",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_T,Qt::NoModifier,"t",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheU_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_U,Qt::ShiftModifier,"U",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_U,Qt::NoModifier,"u",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheV_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_V,Qt::ShiftModifier,"V",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_V,Qt::NoModifier,"v",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheW_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_W,Qt::ShiftModifier,"W",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_W,Qt::NoModifier,"w",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheX_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_X,Qt::ShiftModifier,"X",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_X,Qt::NoModifier,"x",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheY_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Y,Qt::ShiftModifier,"Y",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Y,Qt::NoModifier,"y",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}

void Clavier::on_ToucheZ_pressed(){
    if(ui->ToucheMaj->isChecked()){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Z,Qt::ShiftModifier,"Z",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }else{

        QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Z,Qt::NoModifier,"z",true);
        QCoreApplication::sendEvent(mother->focusWidget(),&event);
    }
}






/*
void Clavier::on_ToucheOk_pressed(){
    if(cache){
        afficher();
    }else{
        cacher();
    }
}
*/

void Clavier::on_ToucheArr_pressed(){
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Backspace,Qt::NoModifier);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
}

void Clavier::on_ToucheSpace_pressed()
{
    QKeyEvent event =QKeyEvent(QEvent::KeyPress,Qt::Key_Space,Qt::NoModifier," ",true);
    QCoreApplication::sendEvent(mother->focusWidget(),&event);
}


/*
void Clavier::cacher()
{

    for(int i =0; i < ui->groupBox->children().size(); i++)
    {
        QWidget * w = qobject_cast<QWidget*>(ui->groupBox->children().at(i));
        if(w != 0){
            w->hide();
        }
    }

    ui->ToucheOk->setVisible(true);
    ui->ToucheOk->setText("SHOW");

    cache = true;

}

void Clavier::afficher()
{

    for(int i =0; i < ui->groupBox->children().size(); i++)
    {
        QWidget * w = qobject_cast<QWidget*>(ui->groupBox->children().at(i));
        if(w != 0){
            w->show();
        }
    }

    ui->ToucheOk->setText("HIDE");
    cache = false;
}



*/

void Clavier::on_ToucheMaj_clicked(bool checked)
{
    if(checked){
        ui->ToucheA->setText("A");
        ui->ToucheB->setText("B");
        ui->ToucheC->setText("C");
        ui->ToucheD->setText("D");
        ui->ToucheE->setText("E");
        ui->ToucheF->setText("F");
        ui->ToucheG->setText("G");
        ui->ToucheH->setText("H");
        ui->ToucheI->setText("I");
        ui->ToucheJ->setText("J");
        ui->ToucheK->setText("K");
        ui->ToucheL->setText("L");
        ui->ToucheM->setText("M");
        ui->ToucheN->setText("N");
        ui->ToucheO->setText("O");
        ui->ToucheP->setText("P");
        ui->ToucheQ->setText("Q");
        ui->ToucheR->setText("R");
        ui->ToucheS->setText("S");
        ui->ToucheT->setText("T");
        ui->ToucheU->setText("U");
        ui->ToucheV->setText("V");
        ui->ToucheW->setText("W");
        ui->ToucheX->setText("X");
        ui->ToucheY->setText("Y");
        ui->ToucheZ->setText("Z");
    }else{
        ui->ToucheA->setText("a");
        ui->ToucheB->setText("b");
        ui->ToucheC->setText("c");
        ui->ToucheD->setText("d");
        ui->ToucheE->setText("e");
        ui->ToucheF->setText("f");
        ui->ToucheG->setText("g");
        ui->ToucheH->setText("h");
        ui->ToucheI->setText("i");
        ui->ToucheJ->setText("j");
        ui->ToucheK->setText("k");
        ui->ToucheL->setText("l");
        ui->ToucheM->setText("m");
        ui->ToucheN->setText("n");
        ui->ToucheO->setText("o");
        ui->ToucheP->setText("p");
        ui->ToucheQ->setText("q");
        ui->ToucheR->setText("r");
        ui->ToucheS->setText("s");
        ui->ToucheT->setText("t");
        ui->ToucheU->setText("u");
        ui->ToucheV->setText("v");
        ui->ToucheW->setText("w");
        ui->ToucheX->setText("x");
        ui->ToucheY->setText("y");
        ui->ToucheZ->setText("z");
    }
}


